
$(function(){
	lookDetail(GetQueryString("serviceId"));
	lookcustom();
	$("#wuwui").click(function(){
		judgeServiceOrder(GetQueryString("serviceId"));
	})
})
//GetQueryString("id")
function judgeServiceOrder(serviceId){
	var userid = $('#useridoflogin').val();
	$.ajax({
		url:Server + "/app/exp/judgeServiceOrder",
		//url:"http://localhost:8080/share_ins/app/exp/judgeServiceOrder",
		Type:"POST",
		data:{
			"serviceId":serviceId,
			"cuId":userid
		},
		dataType:"JSON",
		success : function(data) {
			if(data.status == "200"){
			    addService(serviceId);
			}else if(data.status == "500"){
				alert(data.msg);
			}
		},
		error:function(data) {
			alert("服务器错误,请联系管理员.");
		}
	});
}
function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			}

function lookDetail(serviceId){
	//alert(ll);
	$.ajax({
		//"url" : "http://127.0.0.1/app/exp/lookappointService",
		"url" : Server + "/app/exp/lookappointService",
		"type" : "Post",
		"dataType" : "Json",
		"data" : {
			"serviceId" : serviceId 
		},
		success : function(data){
			var m=data;
			//alert(m.serviceName);
			//alert(m[0].serviceName);name1
			$("#name1").html(data.serviceName);
			$("#name").html(data.serviceName);
			$("#time").html(data.getTime);
			$("#serviceImg").attr('src',data.ssimagelist[0].imagePath);
			$('#readOnly').raty({ readOnly: true, score: data.avenger});
			
		}
	})
}
function lookcustom(){
	//alert(ll);
	var userid = $('#useridoflogin').val();
	$.ajax({
		"url" : Server + "/app/exp/lookcustom",
		//"url" : "http://127.0.0.1/app/exp/lookcustom",
		"type" : "Post",
		"dataType" : "Json",
		"data" : {
			"uid": userid 
		},
		success : function(data){
			var m=data;
			//alert(m.serviceName);
			//alert(m[0].serviceName);name1
			$("#person").val(data.username);
			$("#phone").val(data.mobile);
			
		}
	})
}

function addService(serviceId){
	var price = getCookie("ServicePice");
	console.log(price)
	var content = $("#describe").val();
	var userid = $('#useridoflogin').val();
	$.ajax({
		"url" : Server + "/app/exp/addServiceOrder",
		//"url":"http://localhost:8080/share_ins/app/exp/addServiceOrder",
		"type" : "Post",
		//"dataType" : "JSON",
		async:true,
		"data" : {
			"cuid": userid,
			"content":content,
			"serviceId":serviceId,
			"price":price
		},
		success : function(data){
			alert("预约成功");
			$(location).attr('href', "serviceDetail14_2?serviceId=" + serviceId);
		},
		error : function(data){
			alert("预约失败");
		}
		
	})
}
function getCookie(c_name) {
	if(document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");//获取字符串的起点
		if(c_start != -1) {
			c_start = c_start + c_name.length + 1;//获取值的起点
			c_end = document.cookie.indexOf(";", c_start);//获取结尾处
			if(c_end == -1) c_end = document.cookie.length;//如果是最后一个，结尾就是cookie字符串的结尾
			return decodeURI(document.cookie.substring(c_start, c_end));//截取字符串返回
		}
	}
	return "";
}